package com.xuegao.xuegaoremotelogin.mvc;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * <br/> @PackageName：com.xuegao.xuegaoremotelogin.mvc
 * <br/> @ClassName：AddInterceptors
 * <br/> @Description：
 * <br/> @author：xuegao
 * <br/> @date：2021/03/04 21:00
 */
@Configuration
public class AddInterceptors implements WebMvcConfigurer {

    @Autowired
    private LoginInterceptor loginInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        InterceptorRegistration interceptorRegistration = registry.addInterceptor(loginInterceptor);
        /**
         * 添加拦截的路径
         * /为根路径
         * /*为一级路径
         * /** 为所有路径包括多级
         */
        interceptorRegistration.addPathPatterns("/**");
        // 排除不拦截的，包括自己登录的页面不用拦截
        interceptorRegistration.excludePathPatterns("/login");
    }

    // 配置静态资源路径
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
        registry.addResourceHandler("/templates/**").addResourceLocations("classpath:/templates/**");
        // ico
        registry.addResourceHandler("/favicon.ico").addResourceLocations("classpath:/static/");
    }
}